package com.jy.wms.common.base;


import com.joyi.gate.comm.SessionInfo;
import com.joyi.gate.safety.vo.UserInfo;
import com.jy.wms.common.SpringUtil;
import com.jy.wms.dao.WmsShipmentOrderMapper;
import com.jy.wms.pojo.SysHz;
import org.jeecgframework.poi.handler.impl.ExcelDataHandlerDefaultImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.List;
import java.util.Map;


public class ShipmentOrderMapImportHanlder extends ExcelDataHandlerDefaultImpl {
    WmsShipmentOrderMapper wmsShipmentOrderMapper = SpringUtil.getBean(WmsShipmentOrderMapper.class);
    private static Logger log = LoggerFactory.getLogger(WmsShipmentOrderMapper.class);
    @Override
    public void setMapValue(Map<String, Object> map, String originKey, Object value) {
        System.out.print("value:" + value);
        log.info("value:" + value);
        /*if (value instanceof Double) {
            map.put(getRealKey(originKey), PoiPublicUtil.doubleToString((Double) value));
        } else {
            map.put(getRealKey(originKey), value != null ? value.toString() : null);
        }*/

        if (value instanceof Double) {
            NumberFormat nf = new DecimalFormat("#");
            value = nf.format(value);
        }
        if(originKey!="" && originKey!=null){
            map.put(getRealKey(originKey), value != null ? value.toString() : null);
        }



    }

    private String getRealKey(String originKey) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession session = request.getSession();
        UserInfo userinfo = (UserInfo) session.getAttribute(SessionInfo.USER_INFO);//用户信息
        String ckid = String.valueOf(userinfo.getUser().getOrgId().get(0));//仓库id
        List<SysHz> hz = (List) session.getAttribute(BaseSessionInfo.SessionConsignor);
        String hzid = null;
        if (hz.size() > 0) {
            hzid = hz.get(0).getHzid();
        }


        System.out.println("originKey:" + originKey);
            log.info("originKey:" + originKey);
        // WmsOwnerShipmentorderconfig wmsOwnerShipmentorderconfig = wmsShipmentOrderMapper.getWmsShipmentOrderConfig(hzid);

        //if (wmsOwnerShipmentorderconfig != null) {
        if (originKey.equals("渠道")) {
            return "qdmc";
        }
        if (originKey.equals("订货服务机构")) {
            return "qdbh";
        }
        if (originKey.equals("订单号")) {//发运编号
            return "fybh";
        }
        if (originKey.equals("关联单号")) {
            return "gldh";
        }
        if (originKey.equals("发货方式")) {
            return "jhfs";
        }
        if (originKey.equals("订单类型")) {
            return "fylx";
        }
        if (originKey.equals("收货人姓名")) {//联系人姓名，客户名称
            return "lxrxm";
        }
        if (originKey.equals("省份")) {
            return "sheng";
        }
        if (originKey.equals("城市")) {
            return "shi";
        }
        if (originKey.equals("收货地址")) {
            return "khdz";
        }
        if (originKey.equals("联系电话")) {//电话
            return "lxrdh";
        }
        if (originKey.equals("支付日期")) {//ERP创建时间
            return "khcjsj";
        }
        if (originKey.equals("产品编码")) {//货品编号
            return "hpbh";
        }
        if (originKey.equals("产品名称")) {
            return "hpmc";
        }
        if (originKey.equals("数量")) {
            return "yqsl";
        }
        if (originKey.equals("备注")) {
            return "bz";
        }
        if (originKey.equals("预警日期")) {
            return "yjrq";
        }



        if (originKey.equals("发起部门")) {
            return "fqbm";
        }
        if (originKey.equals("发起人")) {
            return "fqr";
        }
        if (originKey.equals("会员编号")) {//，客户编号
            return "hybh";
        }
        if (originKey.equals("会员姓名")) {
            return "hyxm";
        }
        if (originKey.equals("运费承担方")) {
            return "yfcdf";
        }
        if (originKey.equals("收货人国家")) {
            return "country";
        }
        if (originKey.equals("县区")) {
            return "xq";
        }
        if (originKey.equals("特定物流单号")) {
            return "tdwldh";
        }

        if (originKey.equals("是否抵扣行")) {
            return "bs";
        }

      /*  if(originKey.equals("抵扣数量")){
            return "dksl";
        }*/











           /* if (originKey.equals(wmsOwnerShipmentorderconfig.getShdz())) {
                return "shdz";
            }
            if (originKey.equals(wmsOwnerShipmentorderconfig.getKhmc())) {
                return "khmc";
            }
            if (originKey.equals(wmsOwnerShipmentorderconfig.getKhbh())) {
                return "khbh";
            }
            if (originKey.equals(wmsOwnerShipmentorderconfig.getHpbh())) {
                return "hpbh";
            }
            if (originKey.equals(wmsOwnerShipmentorderconfig.getHpsl())) {
                return "hpsl";
            }
            if (originKey.equals(wmsOwnerShipmentorderconfig.getHplsje())) {
                return "hplsje";
            }
            if (originKey.equals(wmsOwnerShipmentorderconfig.getDdrq())) {
                return "ddrq";
            }
            if (originKey.equals(wmsOwnerShipmentorderconfig.getFhrq())) {
                return "fhrq";
            }*/
        //  }
        return "";
    }
}
